package com.ruoyi.web.controller.app;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yanjing.domain.Area;
import com.ruoyi.yanjing.domain.ElectricityPole;
import com.ruoyi.yanjing.domain.Line;
import com.ruoyi.yanjing.domain.MonitorPoint;
import com.ruoyi.yanjing.domain.req.PointMessageToTopicReq;
import com.ruoyi.yanjing.domain.req.QueryMessageByTopicReq;
import com.ruoyi.yanjing.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * app信息Controller
 *
 * @author whz
 * @date 2024-11-18
 */
@Api("App聚合查询管理")
@RestController
@RequestMapping("/app")
public class AppController extends BaseController{

    @Autowired
    private IElectricityPoleService electricityPoleService;

    @Autowired
    private IMonitorPointService monitorPointService;

    @Autowired
    private IAreaService areaService;

    @Autowired
    private ILineService lineService;

    @Autowired MqttService mqttService;



    /**
     * 查询区域列表-不分页
     */
    @ApiOperation("区域---查询区域列表-不分页")
    @GetMapping("/area/selectAllAreaList")
    public AjaxResult selectAllAreaList(Area area)
    {
        return success(areaService.selectAreaList(area));
    }

    /**
     * 获取区域详细信息
     */
    @ApiOperation("区域---获取区域详细信息")
    @GetMapping(value = "/area/{id}")
    public AjaxResult getAreaInfo(@PathVariable("id") String id)
    {
        return success(areaService.selectAreaById(id));
    }


    /**
     * 查询线路列表-不分页
     */
    @ApiOperation("线路---查询线路列表-不分页")
    @GetMapping("/line/selectAllLineList")
    public AjaxResult selectAllLineList(Line line)
    {
        return success(lineService.selectLineList(line));
    }

    /**
     * 获取线路信息详细信息
     */
    @ApiOperation("线路---获取线路信息详细信息")
    @GetMapping(value = "/line/{id}")
    public AjaxResult getLineInfo(@PathVariable("id") String id)
    {
        return success(lineService.selectLineById(id));
    }


    /**
     * 查询电杆信息列表-不分页
     */
    @ApiOperation("电杆---查询电杆信息列表-不分页")
    @GetMapping("/pole/selectAllPoleList")
    public AjaxResult selectAllPoleList(ElectricityPole electricityPole)
    {
        return success(electricityPoleService.selectElectricityPoleList(electricityPole));
    }

    /**
     * 获取电杆信息详细信息
     */
    @GetMapping(value = "/pole/{id}")
    @ApiOperation("电杆---获取电杆信息详细信息")
    public AjaxResult getPoleInfo(@PathVariable("id") String id)
    {
        return success(electricityPoleService.selectElectricityPoleById(id));
    }

    /**
     * 修改电杆信息
     */
    @ApiOperation("电杆---修改电杆信息")
    @Log(title = "电杆信息", businessType = BusinessType.UPDATE)
    @PostMapping("/pole/update")
    public AjaxResult edit(@RequestBody ElectricityPole electricityPole)
    {
        return toAjax(electricityPoleService.updateElectricityPole(electricityPole));
    }



    /**
     * 查询监测点位所有信息列表-不分页
     */
    @ApiOperation("点位---查询监测点位所有信息列表-不分页")
    @GetMapping("/monitor/selectAllPointList")
    public AjaxResult selectAllPointList(MonitorPoint monitorPoint)
    {
        return success(monitorPointService.selectMonitorPointList(monitorPoint));
    }


    /**
     * 查询监测点位设备所有信息列表-不分页
     */
    @ApiOperation("点位---查询监测点位设备所有信息列表-不分页")
    @GetMapping("/monitor/selectAllPointDeviceList")
    public AjaxResult selectAllPointDeviceList(MonitorPoint monitorPoint)
    {
        return success(monitorPointService.selectAllPointDeviceList(monitorPoint));
    }

    /**
     * 获取监测点位信息详细信息
     */
    @ApiOperation("点位---获取监测点位信息详细信息")
    @GetMapping(value = "/monitor/{id}")
    public AjaxResult getMonitorInfo(@PathVariable("id") String id)
    {
        return success(monitorPointService.selectMonitorPointById(id));
    }

    /**
     * 新增监测点位信息
     */
    @ApiOperation("点位---新增点位设备")
    @Log(title = "监测点位信息", businessType = BusinessType.INSERT)
    @PostMapping("/monitor/insert")
    public AjaxResult add(@RequestBody MonitorPoint monitorPoint)
    {
        return toAjax(monitorPointService.insertMonitorPoint(monitorPoint));
    }



    /**
     * 订阅主题
     */
    @ApiOperation("MQTT---订阅主题")
    @Log(title = "订阅主题", businessType = BusinessType.INSERT)
    @PostMapping("/mqtt/addTopic")
    public AjaxResult addTopic(@RequestBody ElectricityPole electricityPole)
    {
        return success(mqttService.addTopic(electricityPole));
    }

    /**
     * 下发消息到主题
     */
    @ApiOperation("MQTT---下发消息到主题")
    @Log(title = "下发消息到主题", businessType = BusinessType.OTHER)
    @PostMapping("/mqtt/addMessageToTopic")
    public AjaxResult addTopic(@RequestBody PointMessageToTopicReq req)
    {
        return success(mqttService.addMessageToTopic(req));
    }

    /**
     * 下发网关回复查询消息到主题
     */
    @ApiOperation("MQTT---下发网关回复查询消息到主题")
    @Log(title = "下发网关回复查询消息到主题", businessType = BusinessType.OTHER)
    @PostMapping("/mqtt/addQueryMessageToTopic")
    public AjaxResult addQueryMessageToTopic(@RequestBody QueryMessageByTopicReq req)
    {
        return success(mqttService.addQueryMessageToTopic(req));
    }

}
